package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-03-24
 * Time: 20:51
 */
//sleep-休眠 是Thread中的静态方法 单位ms1

class MyThread extends Thread {
    //run是线程的入口方法
    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Hello t");
        }
    }
}

public class ThreadDemo1 {
    //这种方式是使用Thread 的run来描述线程入口
    public static void main(String[] args) throws InterruptedException {
        Thread t = new MyThread();
        // start 启动线程。start两次，第二次会失败
        //
        t.start();

        while (true) {
            Thread.sleep(1000);
            System.out.println("hello main");
        }
    }
}
